﻿/*
 * File:            Color.cs
 * Last changed:    27-08-2011
 * Purpose:         Standard colors and color conversion
 * Author:          Lars Diederich
 * Copyright:       (C) L.Diederich 2011
 * Product:         UnifyGUI
 *
 * Copyright (c) 2011 Lars Diederich
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 */


using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

namespace UnifyGUI
{
    public struct Color
    {
        private int _colorR;
        private int _colorG;
        private int _colorB;
        private int _colorA;
        private List<int> _colorList;

        public int IntR
        {
            get
            {
                return this._colorR;
            }
            set
            {
                this._colorR = value;
            }
        }

        public int IntG
        {
            get
            {
                return this._colorG;
            }
            set
            {
                this._colorG = value;
            }
        }

        public int IntB
        {
            get
            {
                return this._colorB;
            }
            set
            {
                this._colorB = value;
            }
        }

        public int IntA
        {
            get
            {
                return this._colorA;
            }
            set
            {
                this._colorA = value;
            }
        }

        public float FloatR
        {
            get
            {
                float f = this._colorR / 255.0f;
                return f;
            }
        }

        public float FloatG
        {
            get
            {
                float f = this._colorG / 255.0f;
                return f;
            }
        }

        public float FloatB
        {
            get
            {
                float f = this._colorB / 255.0f;
                return f;
            }
        }

        public float FloatA
        {
            get
            {
                float f = this._colorA / 255.0f;
                return f;
            }
        }

        public List<int> GetIntList
        {
            get
            {
                this._colorList.Clear();
                this._colorList.Add(this._colorR);
                this._colorList.Add(this._colorG);
                this._colorList.Add(this._colorB);
                this._colorList.Add(this._colorA);

                return this._colorList;
            }
        }

        public void SetFromRGBA(int R, int G, int B, int A)
        {
            this._colorR = R;
            this._colorG = G;
            this._colorB = B;
            this._colorA = A;
        }

        public void SetFromHexString(string hexString)
        {
            string hexR = hexString.Substring(1, 2);
            string hexG = hexString.Substring(3, 2);
            string hexB = hexString.Substring(5, 2);
            string hexA = hexString.Substring(7, 2);

            this._colorR = ConvertHexToInt(hexR);
            this._colorG = ConvertHexToInt(hexG);
            this._colorB = ConvertHexToInt(hexB);
            this._colorA = ConvertHexToInt(hexA);
        }

        private int ConvertHexToInt(string hex)
        {
            int value = 0;
            int digitValue = 1;
            hex = hex.ToUpper();
            char[] hexDigits = hex.ToCharArray(0, hex.Length);

            for (int i = hex.Length - 1; i >= 0; i--)
            {
                int digit = 0;
                if (hexDigits[i] >= '0' && hexDigits[i] <= '9')
                {
                    digit = hexDigits[i] - '0';
                }
                else if (hexDigits[i] >= 'A' && hexDigits[i] <= 'F')
                {
                    digit = hexDigits[i] - 'A' + 10;
                }
                else
                {
                    // Not a hex string
                    return -1;
                }

                value += digit * digitValue;
                digitValue *= 16;
            }

            return value;
        }
    }

    public static class KnownColor
    {
        public static string AliceBlue
        {
            get
            {
                return "#F0F8FFFF";
            }
        }
        public static string AntiqueWhite
        {
            get
            {
                return "#FAEBD7FF";
            }
        }
        public static string Aquamarine
        {
            get
            {
                return "#7FFFD4FF";
            }
        }
        public static string Aqua
        {
            get
            {
                return "#00FFFFFF";
            }
        }
        public static string Azure
        {
            get
            {
                return "#F0FFFFFF";
            }
        }
        public static string Beige
        {
            get
            {
                return "#F5F5DCFF";
            }
        }
        public static string Bisque
        {
            get
            {
                return "#FFE4C4FF";
            }
        }
        public static string Black
        {
            get
            {
                return "#000000FF";
            }
        }
        public static string BlanchedAlmond
        {
            get
            {
                return "#FFEBCDFF";
            }
        }
        public static string Blue
        {
            get
            {
                return "#0000FFFF";
            }
        }
        public static string BlueViolet
        {
            get
            {
                return "#8A2BE2FF";
            }
        }
        public static string Brown
        {
            get
            {
                return "#A52A2AFF";
            }
        }
        public static string BurlyWood
        {
            get
            {
                return "#DEB887FF";
            }
        }
        public static string CadetBlue
        {
            get
            {
                return "#5F9EA0FF";
            }
        }
        public static string Chartreuse
        {
            get
            {
                return "#7FFF00FF";
            }
        }
        public static string Chocolate
        {
            get
            {
                return "#D2691EFF";
            }
        }
        public static string Coral
        {
            get
            {
                return "#FF7F50FF";
            }
        }
        public static string CornflowerBlue
        {
            get
            {
                return "#6495EDFF";
            }
        }
        public static string Cornsilk
        {
            get
            {
                return "#FFF8DCFF";
            }
        }
        public static string Crimson
        {
            get
            {
                return "#DC143CFF";
            }
        }
        public static string Cyan
        {
            get
            {
                return "#00FFFFFF";
            }
        }
        public static string DarkBlue
        {
            get
            {
                return "#00008BFF";
            }
        }
        public static string DarkCyan
        {
            get
            {
                return "#008B8BFF";
            }
        }
        public static string DarkGoldenRod
        {
            get
            {
                return "#B8860BFF";
            }
        }
        public static string DarkGray
        {
            get
            {
                return "#A9A9A9FF";
            }
        }
        public static string DarkKhaki
        {
            get
            {
                return "#BDB76BFF";
            }
        }
        public static string DarkMagenta
        {
            get
            {
                return "#8B008BFF";
            }
        }
        public static string DarkOliveGreen
        {
            get
            {
                return "#556B2FFF";
            }
        }
        public static string Darkorange
        {
            get
            {
                return "#FF8C00FF";
            }
        }
        public static string DarkOrchid
        {
            get
            {
                return "#9932CCFF";
            }
        }
        public static string DarkRed
        {
            get
            {
                return "#8B0000FF";
            }
        }
        public static string DarkSalmon
        {
            get
            {
                return "#E9967AFF";
            }
        }
        public static string DarkSeaGreen
        {
            get
            {
                return "#8FBC8FFF";
            }
        }
        public static string DarkSlateBlue
        {
            get
            {
                return "#2F4F4FFF";
            }
        }
        public static string DarkSlateGray
        {
            get
            {
                return "#2F4F4FFF";
            }
        }
        public static string DarkTurquoise
        {
            get
            {
                return "#00CED1FF";
            }
        }
        public static string DarkViolet
        {
            get
            {
                return "#9400D3FF";
            }
        }
        public static string DeepPink
        {
            get
            {
                return "#FF1493FF";
            }
        }
        public static string DeepSkyBlue
        {
            get
            {
                return "#00BFFFFF";
            }
        }
        public static string DimGray
        {
            get
            {
                return "#696969FF";
            }
        }
        public static string DodgerBlue
        {
            get
            {
                return "#1E90FFFF";
            }
        }
        public static string FireBrick
        {
            get
            {
                return "#B22222FF";
            }
        }
        public static string FloralWhite
        {
            get
            {
                return "#FFFAF0FF";
            }
        }
        public static string ForestGreen
        {
            get
            {
                return "#228B22FF";
            }
        }
        public static string Fuchsia
        {
            get
            {
                return "#FF00FFFF";
            }
        }
        public static string Gainsboro
        {
            get
            {
                return "#DCDCDCFF";
            }
        }
        public static string GhostWhite
        {
            get
            {
                return "#F8F8FFFF";
            }
        }
        public static string Gold
        {
            get
            {
                return "#FFD700FF";
            }
        }
        public static string GoldenRod
        {
            get
            {
                return "#DAA520FF";
            }
        }
        public static string Gray
        {
            get
            {
                return "#808080FF";
            }
        }
        public static string Green
        {
            get
            {
                return "#008000FF";
            }
        }
        public static string GreenYellow
        {
            get
            {
                return "#ADFF2FFF";
            }
        }
        public static string HoneyDew
        {
            get
            {
                return "#F0FFF0FF";
            }
        }
        public static string HotPink
        {
            get
            {
                return "#FF69B4FF";
            }
        }
        public static string IndianRed
        {
            get
            {
                return "#CD5C5CFF";
            }
        }
    }
}
